package com.mjh.zhujianju.controller.supervise;

import com.livew.framework.exception.XTBusinessException;
import com.mjh.zhujianju.model.supervise.SupervisionDiscussEO;
import com.mjh.zhujianju.model.supervise.SupervisionEstimateEO;
import com.mjh.zhujianju.service.supervise.SupervisionDiscussService;
import com.mjh.zhujianju.service.supervise.SupervisionEstimateService;
import com.mjh.zhujianju.util.ApiConstant;
import com.mjh.zhujianju.util.JsonResult;
import com.mjh.zhujianju.vo.supervision.SupervisionEstimateVO;
import com.mjh.zhujianju.vo.supervision.SupervisionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Alex
 * @version: V1.0
 * @project: zhujianju
 * @package: com.mjh.zhujianju.controller.supervise
 * @description: description
 * @date: 2018/9/5
 * @time: 上午8:46
 */
@RestController
@RequestMapping("/discuss")
@Api("4.督办->交流")
public class SupervisionDiscussController {

	@Autowired
	private SupervisionDiscussService supervisionDiscussService;

	@ApiOperation(value="督办->交流", notes="督办人员互相交流")
	@RequestMapping(value = "/addDiscuss", method = RequestMethod.POST)
	@ApiImplicitParam(name = "交流实体类", value = "supervisionDiscussEO", required = true, dataType = "SupervisionDiscussEO")
	public ResponseEntity<JsonResult> addDiscuss (@RequestBody SupervisionDiscussEO supervisionDiscussEO){
		JsonResult result = new JsonResult();
		try {
			supervisionDiscussService.saveInfo(supervisionDiscussEO);
			result.setResult("发布成功");
			result.setStatus(ApiConstant.MSG_SUCCESS);
		}catch (XTBusinessException e){
			result.setResult(e.getClass().getName() + ":" + e.getMessage());
			result.setStatus(ApiConstant.MSG_ERROR);
			e.printStackTrace();
		}
		return ResponseEntity.ok(result);
	}

	@ApiOperation(value="督办->查看交流信息", notes="根据督办id查看督办交流信息")
	@RequestMapping(value = "/showDiscuss/{id}", method = RequestMethod.GET)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "督办主键", required = true, dataType = "Long", paramType = "path")
	}
	)
	public ResponseEntity<JsonResult> showDiscuss (@PathVariable(value = "id")Long id){
		JsonResult result = new JsonResult();
		SupervisionVO supervisionEstimateVO = null;
		try {
			supervisionEstimateVO = supervisionDiscussService.findSupervisionDiscussById(id);
			result.setResult(supervisionEstimateVO);
			result.setStatus(ApiConstant.MSG_SUCCESS);
		} catch (XTBusinessException e) {
			result.setStatus(ApiConstant.MSG_ERROR);
			result.setResult(e.getClass().getName() + ":" + e.getMessage());
			e.printStackTrace();
		}

		return ResponseEntity.ok(result);
	}
}
